// pages/helpCarry/helpCarry.js、
const A =  wx.cloud.database().collection("orders");
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
let logFunction = require("../../utils/Log.js");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    // currentDate: '11:00',
    minHour: 10,
    maxHour: 20,
    show: true,
    pri: '',
    priNum: 0,
    thing: '',
    // pakingLocation: "1"
  },
  selectLocation() {
    wx.navigateTo({
      url: '../addAddress/addAddress?data=pakingLocation',
    })
  },
  selectLocation2() {
    wx.navigateTo({
      url: '../addAddress/addAddress?data=getLocation',
    })
  },
  getUserInfo(event) {
    console.log(event.detail);
  },
  pakingLocationFun(e) {
    console.log(e.detail);
    this.setData({
      pakingLocation: e.detail,
    })
  },
  getLocationFun(e) {
    this.setData({
      getLocation: e.detail,
    })
  },

  thingChange(e) {
    // console.log(e);
    this.setData({
      thing: e.detail.value,
    })
  },

  psFun(e) {
    console.log(e);
    this.setData({
      ps: e.detail.value
    })
  },
  onCheckChange(event) {
    this.setData({
      checked: event.detail,
    });
    
  },
  onChange(event) {
    this.setData({
      checked: event.detail,
    });
  },
  onSubmit() {
    console.log(this);
    this.getCurrentTime();
    // if (!getApp().globalData.userInfo) {
      logFunction.logFunction.getUserProfile(this);
    // }
    // else{
      if (getApp().globalData.judgeUser) {

          console.log(this.__data__.thing);
    A.add({
      data: {
        pakingLocation: this.__data__.pakingLocation,
        getLocation: this.__data__.getLocation,
        time: this.__data__.time,
        thing: this.__data__.thing,
        priNum: this.__data__.priNum,
        ps: this.__data__.ps,
        type: "校园帮带",
        checked: this.__data__.checked,
        // userInfo.avatarUrl
        avatarUrl: getApp().globalData.userInfo.avatarUrl,
        nickName: getApp().globalData.userInfo.nickName,
        currentTime: this.__data__.currentTime,
      },
      success: (result) => {
        // console.log(result);
        Toast('SUCCESS!');
        setTimeout(() => {
          wx.navigateBack();
        }, 1000);
        
      },
      fail: (res) => {},
      complete: (res) => {
        
      }
    })
    }
    
  },

  onClose() {
    this.setData({ show: false });
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(getApp().globalData.userInfo);
    console.log(A);
    // A.get({
    //   success(e){
        
    //       console.log(e);
    //       console.log(e.data[0].wzx);
    //   }
    // })
    // A.add({
    //   // data 字段表示需新增的 JSON 数据
    //   data: {
    //     value: "123"
    //   },
    //   success: function(res) {
    //     // res 是一个对象，其中有 _id 字段标记刚创建的记录的 id
    //     console.log(res)
    //   }
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  getCurrentTime() {
    var month=new Date();
    console.log(month.getHours()+":"+month.getMinutes());
    let currentTime = month.getHours()+":"+month.getMinutes();
    this.setData({
      currentTime,
    })
    return currentTime;
  },
  onReady() {
    console.log(this.__data__.pri);
    let currentTime = this.getCurrentTime();
    this.setData({
      time: currentTime,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log(this);
  },
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  logFun() {
    // console.log();
    

    
  },
  onChangePri(e) {
    console.log(123);
    
    if(e.detail === '') {
      this.setData(
        {priNum: 0}
      );
    }
    else
      this.setData(
      {priNum: parseInt(e.detail)}
    );
    console.log(typeof this.__data__.pri);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})